package sam.learning.mybatis.xml.custom;

import org.apache.ibatis.session.SqlSession;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.List;

/**
 * @Author taozhaoyang
 * @Description //TODO 自定义mapper的代理类$
 * @Date 2018/8/15 14:37
 **/
public class MyMapperProxy<T> implements InvocationHandler {

   private SqlSession sqlSession;

   private Class<T> mapperinterface;

    public MyMapperProxy(SqlSession sqlSession, Class<T> mapperinterface) {
        this.sqlSession = sqlSession;
        this.mapperinterface = mapperinterface;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // mapper接口的全限定名称+调用方法名称，组成Id
        String  statement = mapperinterface.getCanonicalName()+"."+method.getName();
        List<T> list = sqlSession.selectList(statement);
        return list;
    }
}
